/*
 * @Author: 高瑞寒 15932717091@163.com
 * @Date: 2022-05-17 22:48:58
 * @LastEditTime: 2022-05-19 10:22:24
 * @LastEditors: 高瑞寒 15932717091@163.com
 * @Description:
 */
import { createRouter, createWebHashHistory } from 'vue-router'
import ArticleRanking from './modules/ArticleRanking'
import ArticleCreate from './modules/ArticleCreate'
import PermissionList from './modules/PermissionList'
import RoleList from './modules/RoleList'
import UserManage from './modules/UserManage'
import layout from '@/layout/index'
import store from '@/store'
// 私有路由表
export const privateRoutes = [
  ArticleRanking, ArticleCreate, PermissionList, RoleList, UserManage
]
// 公共路由表
export const publicRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login')
  },
  {
    path: '/',
    component: layout,
    redirect: '/profile',
    children: [
      {
        path: '/profile',
        name: 'profile',
        component: () => import('@/views/profile/index'),
        meta: {
          title: 'profile',
          icon: 'el-icon-user'
        }
      },
      {
        path: '/404',
        name: '404',
        component: () => import('@/views/error-page/404')
      },
      {
        path: '/401',
        name: '401',
        component: () => import('@/views/error-page/401')
      }
    ]
  }

]

const router = createRouter({
  history: createWebHashHistory(),
  routes: publicRoutes
})

export function resetRouter() {
  if (store.getters.userInfo &&
    store.getters.userInfo.permission &&
    store.getters.userInfo.permission.menus) {
    const menus = store.getters.userInfo.permission.menus
    for (const menu of menus) {
      router.removeRoute(menu)
    }
  }
}

export default router
